<p>This is an issue when a function is defined in a nested scope but doesn’t use any variables from that scope, meaning it could be moved to a higher
scope.</p>
<h2>Why is this an issue?</h2>
<p>When functions are defined in nested scopes unnecessarily, it creates several problems:</p>
<p><strong>Performance Impact</strong>: Functions defined inside other functions are recreated every time the outer function runs. This wastes memory
and processing time, especially in frequently called code.</p>
<p><strong>Engine Optimization</strong>: JavaScript engines like V8 have optimization limits. Functions in nested scopes are harder to optimize, which
can slow down your application.</p>
<p><strong>Code Readability</strong>: Functions at higher scopes are easier to find and understand. When a function doesn’t depend on its surrounding
context, placing it at the top level makes the code structure clearer.</p>
<p><strong>Memory Usage</strong>: Each function instance takes up memory. Creating the same function repeatedly in nested scopes increases memory
consumption unnecessarily.</p>
<p>The rule identifies functions that capture no variables from their enclosing scope, meaning they can be safely moved to a higher level without
changing their behavior.</p>
<h3>What is the potential impact?</h3>
<p>Moving functions to appropriate scopes improves application performance by reducing function recreation overhead and enabling better JavaScript
engine optimizations. It also enhances code maintainability by making function dependencies clearer and reducing memory usage in frequently executed
code paths.</p>
<h3>How to fix?</h3>
<p>Move the function declaration to the module level when it doesn’t capture any variables from the enclosing scope.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
export function doFoo(foo) {
	// Does not capture anything from the scope
	function doBar(bar) { // Noncompliant
		return bar === 'bar';
	}

	return doBar;
}
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
function doBar(bar) {
	return bar === 'bar';
}

export function doFoo(foo) {
	return doBar;
}
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/consistent-function-scoping.md">consistent-function-scoping</a>
  </li>
  <li> JavaScript Function Hoisting - <a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting">MDN documentation on JavaScript hoisting
  behavior</a> </li>
  <li> JavaScript Performance Best Practices - <a
  href="https://developer.mozilla.org/en-US/docs/Web/Performance/JavaScript_performance_best_practices">MDN guide on optimizing JavaScript
  performance</a> </li>
  <li> V8 JavaScript Engine Optimization - <a href="https://v8.dev/docs/optimize">Official V8 documentation on JavaScript optimization</a> </li>
</ul>
<h3>Standards</h3>
<ul>
  <li> ESLint: prefer-const - <a href="https://eslint.org/docs/latest/rules/prefer-const">Related ESLint rule for variable declaration
  optimization</a> </li>
</ul>
